const express = require('express')
const { readFileSync } = require("fs");
const { resolve } = require("path");

const router = express.Router()
router.get("/get_comments", (req, res) => {
    const authHeader = req.headers['authorization'];
    const token = authHeader && authHeader.split(' ')[1]; // 从 "Bearer token" 中提取token
    console.log('2222222222222222222', token == 'null');

    if (token == 'null') {
        return res.json({
            code: 401,
            msg: "没有检测到token",
            data: {},
        });
    }
    const comments = JSON.parse(
        readFileSync(resolve(__dirname, "../../data/commemt/data.json"), "utf8")
    );
    res.json({
        code: 200,
        msg: "ok",
        data: {
            comments,
        },
    });
});

//暴露 router
module.exports = router;